﻿using PHRClient.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace PHRClient
{
    public class PatientData
    {
        public int UserId { get; set; }
        public string RecordDate { get; set; }
        public int Weight { get; set; }
        public int BodyTemp { get; set; }
        public int HeartRate { get; set; }
        public int CholestrolTri { get; set; }
        public int CholestrolHdl { get; set; }
        public int CholestrolLdl { get; set; }
        public int BloodPressureSys { get; set; }
        public int BloodPressureDia { get; set; }
        public int PulseRate { get; set; }
        public int Glucose { get; set; }
    }

    [XmlRoot("PatientDetails")]
    public class PatientDataCollection : List<PatientData>
    {
        public static PatientDataCollection Load(string fileName)
        {
            PatientDataCollection dc = new FileInfo(fileName).XmlDeserialize<PatientDataCollection>();

            return dc;
        }

        public void Save(string fileName)
        {
            this.XmlSerialize(fileName);
        }
    }

    public static class PatientDataLoader
    {
        public const string XMLFILE = "data.xml";
        
        public static List<PatientData> getUserDataById(int id)
        {
            List<PatientData> patientDataList = PatientDataCollection.Load(XMLFILE);

            List<PatientData> newList = new List<PatientData>();

            foreach (PatientData patientData in patientDataList)
            {
                if (patientData.UserId.Equals(id))
                {
                    newList.Add(patientData);
                }
            }

            return newList;
        }
    }
}
